public class Solution {
    public String convert(String s, int numRows) {
        // 修正numRows=1直接返回
        if (numRows == 1) return s;
        int len  = s.length();
        StringBuffer[] stringBuffers = new StringBuffer[numRows];
        for (int j = 0; j < numRows; j++) {
            stringBuffers[j] = new StringBuffer();
        }
        boolean direction = true;
        int row = 0;
        for (int i = 0; i < len; i++) {
            stringBuffers[row].append(s.charAt(i));
            if (row >= numRows - 1) {
                direction = false;
            } else if (row <= 0) {
                direction = true;
            }
            if (direction) {
                row++;
            } else {
                row--;
            }
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (StringBuffer sb: stringBuffers) {
            stringBuffer.append(sb.toString());
        }
        return stringBuffer.toString();
    }
}
